package com.example.administrator.telphone;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = (Button) findViewById(R.id.button);
        EditText editText = (EditText) findViewById(R.id.editext);
        final String call = editText.getText().toString();

        button.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(PhoneNumberUtils.isGlobalPhoneNumber(call)) {

                    Intent I = new Intent(Intent.ACTION_CALL, Uri.parse("tel://"+call));
                  
                }
                else{

                    Toast.makeText(MainActivity.this,"您输入的号码不正确，请重新输入",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
